import turtle
turtle.hideturtle()


def goto(point):
    turtle.up()
    turtle.goto(point)
    turtle.down()


point = [0, 0]
index = 1
speed = 1

def snake():
    turtle.clear()
    goto(point)
    turtle.dot(25)
    point[index] += speed
    turtle.ontimer(snake, 3)


def down():
    global index, speed
    index = 1
    speed = -1


def up():
    global index, speed
    index = 1
    speed = 1


def left():
    global index, speed
    index = 0
    speed = -1


def right():
    global index, speed
    index = 0
    speed = 1


turtle.onkeypress(down, "Down")
turtle.onkeypress(up, "Up")
turtle.onkeypress(left, "Left")
turtle.onkeypress(right, "Right")
turtle.listen()
turtle.tracer(False)
snake()
turtle.done()